    
	
	***data paths 
  
   global posted /Volumes/Sans titre/DATA_MICROEU/Posting
   global data /Users/Mathilde/Dropbox/Posted_workers/Data
   
   
   
   **output paths
  global replication_outputs_a /Users/Mathilde/Dropbox/Posted_workers/Replication/TNT_final/Replication_package/Appendix_figures
  global replication_estimates /Users/Mathilde/Dropbox/Posted_workers/Replication/TNT_final/Replication_package/Main_estimates
  global replication_estimates_a /Users/Mathilde/Dropbox/Posted_workers/Replication/TNT_final/Replication_package/Appendix_estimates
  global replication_outputs /Users/Mathilde/Dropbox/Posted_workers/Replication/TNT_final/Replication_package/Main_figures

  global frontalier 1 2 4 5 6 8 9 25 31 39 54 55 57 59 64 65 66 67 68 71 74 90


	
	
	****************************************************
	*. Appendix D2: Raw levels 
	****************************************************

	use "$data/merge_employment_FR_19892015.dta", clear 
	cap drop _m
	merge m:1 code_insee using "$data/initialexposure.dta", keepusing(nbsal2003 Region)
	drop _m 
	drop if year>2015 
	egen totnbsal=sum(nbsal), by(sector)
	g postable=1
	replace postable=0 if totnbsal==0
	*constant variable at the province-level
	egen totemp=sum(employment), by(code_insee year)
	g totemp2003d=totemp if year==2003
	egen totemp2003=min(totemp2003d), by(code_insee)
	gen exposure_pre_pp=(nbsal2003/totemp2003)*100
	
	collapse (sum) employment (mean) pop  exposure_pre_pp, by(postable code_insee year)
	
	
	*Rank of pre-existing exposure 
	egen rankrelempd=xtile(exposure_pre_pp) if postable==1 & year==2004, nq(10) 
	egen rankrelemp=min(rankrelempd), by(code_insee)
	g top=.
	replace top=1 if rankrelemp>9 & rankrelemp!=.
	replace top=0 if rankrelemp<5 & rankrelemp!=.
	drop if top==.
	
    collapse (sum) employment pop, by(postable top year)
	
	g logemp=log(employment)
	g emprel=employment/pop
	foreach y in employment emprel{
	g normp`y'=`y' if year==2003
	egen norm`y'=min(normp`y'), by(top postable)
	g normemp`y'=`y'/norm`y'
	}

	g post=0
	replace post=1 if year>2003
	g interac=0
	replace interac=1 if postable==1 & top==1 & post==1
	g logemprel=log(emprel)

	reg logemprel i.top i.year i.top##i.post if postable==1 & year>1993, ro
    global beta=round(_b[1.top#1.post],.01)
	global se=round(_se[1.top#1.post],.01)

	twoway (connected normempemprel year if top==1 & postable==1 & year>1993, lcolor(cranberry) mcolor(cranberry)) ///
	(connected normempemprel year if top==0 & postable==1 & year>1993, lcolor(dknavy) mcolor(dknavy)), ///
	legend(label(1 "Top 10% Exposure") label(2 "Bottom 40% Exposure") cols(1) ring(0) pos(11)) ylabel(0.7 (0.3) 1.3) ///
	graphregion(fcolor(white) lcolor(white)) ///
	xlabel(1994 (1) 2015, angle(vertical)) xtitle("") ytitle("Share of Working Age Pop. in Postable Sectors (2003=1)") ///
	xline(2004, lcolor(red)) ///
	ttext(1.3 2010 "DiD: $beta($se)", place(e))
    graph export "$replication_outputs_a/FigureD35.pdf", replace	
	
	reg logemp i.top i.year i.top##i.post if postable==1 & year>1993, ro
    global beta=round(_b[1.top#1.post],.001)
	global se=round(_se[1.top#1.post],.01)
	
	twoway (connected normempemployment year if top==1 & postable==1 & year>1993, lcolor(cranberry) mcolor(cranberry)) ///
	(connected normempemployment year if top==0 & postable==1 & year>1993, lcolor(dknavy) mcolor(dknavy)), ///
	legend(label(1 "Top 10% Exposure") label(2 "Bottom 40% Exposure") cols(1) ring(0) pos(11)) ylabel(0.7 (0.3) 1.3) ///
	graphregion(fcolor(white) lcolor(white)) ///
	xlabel(1994 (1) 2015, angle(vertical)) xtitle("") ytitle("Share of Working Age Pop. in Postable Sectors (2003=1)") ///
	xline(2004, lcolor(red)) ///
	ttext(1.3 2010 "DiD: $beta($se)", place(e))
     graph export "$replication_outputs_a/FigureD36e.pdf", replace	
	
	
	reg logemprel i.top i.year i.top##i.post if postable==0 & year>1993, ro
    global beta=round(_b[1.top#1.post],.001)
	global se=round(_se[1.top#1.post],.01)

	twoway (connected normempemprel year if top==1 & postable==0 & year>1993, lcolor(cranberry) mcolor(cranberry)) ///
	(connected normempemprel year if top==0 & postable==0 & year>1993, lcolor(dknavy) mcolor(dknavy)), ///
	legend(label(1 "Top 10% Exposure") label(2 "Bottom 40% Exposure") cols(1) ring(0) pos(11)) ylabel(0.7 (0.3) 1.3) ///
	graphregion(fcolor(white) lcolor(white)) ///
	xlabel(1994 (1) 2015, angle(vertical)) xtitle("") ytitle("Share of Working Age Pop. in Non-Postable Sectors (2003=1)") ///
	xline(2004, lcolor(red)) ///
	ttext(1.3 2010 "DiD: $beta($se)", place(e))

	
	reg logemp i.top i.year i.top##i.post if postable==0 & year>1993, ro
    global beta=round(_b[1.top#1.post],.0001)
	global se=round(_se[1.top#1.post],.01)
	
    twoway (connected normempemployment year if top==1 & postable==0 & year>1993, lcolor(cranberry) mcolor(cranberry)) ///
	(connected normempemployment year if top==0 & postable==0 & year>1993, lcolor(dknavy) mcolor(dknavy)), ///
	legend(label(1 "Top 10% Exposure") label(2 "Bottom 40% Exposure") cols(1) ring(0) pos(11)) ylabel(0.7 (0.3) 1.3) ///
	graphregion(fcolor(white) lcolor(white)) ///
	xlabel(1994 (1) 2015, angle(vertical)) xtitle("") ytitle("Share of Working Age Pop. in Non-Postable Sectors (2003=1)") ///
	xline(2004, lcolor(red)) ///
	ttext(1.3 2010 "DiD: $beta($se)", place(e))
	
	
	
	use "$data/merge_employment_FR_19892015.dta", clear 
	cap drop _m
	merge m:1 code_insee using "$data/initialexposure.dta", keepusing(nbsal2003 Region)
	drop _m 
	drop if year>2015 
	egen totnbsal=sum(nbsal), by(sector)
	g postable=1
	replace postable=0 if totnbsal==0
	*constant variable at the province-level
	egen totemp=sum(employment), by(code_insee year)
	g totemp2003d=totemp if year==2003
	egen totemp2003=min(totemp2003d), by(code_insee)
	gen exposure_pre_pp=(nbsal2003/totemp2003)*100
	
	collapse (sum) employment (mean) pop  exposure_pre_pp, by(postable code_insee year)
	
	
	*Rank of pre-existing exposure 
	egen rankrelempd=xtile(exposure_pre_pp) if postable==1 & year==2004, nq(10) 
	egen rankrelemp=min(rankrelempd), by(code_insee)
	g top=.
	replace top=1 if rankrelemp>9 & rankrelemp!=.
	replace top=0 if rankrelemp<4 & rankrelemp!=.
	drop if top==.
	
    collapse (sum) employment pop, by(postable top year)
	
	g logemp=log(employment)
	g emprel=employment/pop
	foreach y in employment emprel{
	g normp`y'=`y' if year==2003
	egen norm`y'=min(normp`y'), by(top postable)
	g normemp`y'=`y'/norm`y'
	}

	g post=0
	replace post=1 if year>2003
	g interac=0
	replace interac=1 if postable==1 & top==1 & post==1
	g logemprel=log(emprel)

	reg logemprel i.top i.year i.top##i.post if postable==1 & year>1993, ro
    global beta=round(_b[1.top#1.post],.01)
	global se=round(_se[1.top#1.post],.01)

		
	twoway (connected normempemprel year if top==1 & postable==1 & year>1993, lcolor(cranberry) mcolor(cranberry)) ///
	(connected normempemprel year if top==0 & postable==1 & year>1993, lcolor(dknavy) mcolor(dknavy)), ///
	legend(label(1 "Top 10% Exposure") label(2 "Bottom 40% Exposure") cols(1) ring(0) pos(11)) ylabel(0.7 (0.3) 1.3) ///
	graphregion(fcolor(white) lcolor(white)) ///
	xlabel(1994 (1) 2015, angle(vertical)) xtitle("") ytitle("Share of Working Age Pop. in Postable Sectors (2003=1)") ///
	xline(2004, lcolor(red)) ///
	ttext(1.3 2010 "DiD: $beta($se)", place(e))
	 graph export "$replication_outputs_a/FigureD36c.pdf", replace	
	 
	 
	 
	use "$data/merge_employment_FR_19892015.dta", clear 
	cap drop _m
	merge m:1 code_insee using "$data/initialexposure.dta", keepusing(nbsal2003 Region)
	drop _m 
	drop if year>2015 
	egen totnbsal=sum(nbsal), by(sector)
	g postable=1
	replace postable=0 if totnbsal==0
	*constant variable at the province-level
	egen totemp=sum(employment), by(code_insee year)
	g totemp2003d=totemp if year==2003
	egen totemp2003=min(totemp2003d), by(code_insee)
	gen exposure_pre_pp=(nbsal2003/totemp2003)*100
	
	collapse (sum) employment (mean) pop  exposure_pre_pp, by(postable code_insee year)
	
	
	*Rank of pre-existing exposure 
	egen rankrelempd=xtile(exposure_pre_pp) if postable==1 & year==2004, nq(10) 
	egen rankrelemp=min(rankrelempd), by(code_insee)
	g top=.
	replace top=1 if rankrelemp>8 & rankrelemp!=.
	replace top=0 if rankrelemp<4 & rankrelemp!=.
	drop if top==.
	
    collapse (sum) employment pop, by(postable top year)
	
	g logemp=log(employment)
	g emprel=employment/pop
	foreach y in employment emprel{
	g normp`y'=`y' if year==2003
	egen norm`y'=min(normp`y'), by(top postable)
	g normemp`y'=`y'/norm`y'
	}

	g post=0
	replace post=1 if year>2003
	g interac=0
	replace interac=1 if postable==1 & top==1 & post==1
	g logemprel=log(emprel)

	reg logemprel i.top i.year i.top##i.post if postable==1 & year>1993, ro
    global beta=round(_b[1.top#1.post],.01)
	global se=round(_se[1.top#1.post],.01)

		
	twoway (connected normempemprel year if top==1 & postable==1 & year>1993, lcolor(cranberry) mcolor(cranberry)) ///
	(connected normempemprel year if top==0 & postable==1 & year>1993, lcolor(dknavy) mcolor(dknavy)), ///
	legend(label(1 "Top 10% Exposure") label(2 "Bottom 40% Exposure") cols(1) ring(0) pos(11)) ylabel(0.7 (0.3) 1.3) ///
	graphregion(fcolor(white) lcolor(white)) ///
	xlabel(1994 (1) 2015, angle(vertical)) xtitle("") ytitle("Share of Working Age Pop. in Postable Sectors (2003=1)") ///
	xline(2004, lcolor(red)) ///
	ttext(1.3 2010 "DiD: $beta($se)", place(e))
	 graph export "$replication_outputs_a/FigureD36b.pdf", replace	

	


	 
	use "$data/merge_employment_FR_19892015.dta", clear 
	cap drop _m
	merge m:1 code_insee using "$data/initialexposure.dta", keepusing(nbsal2003 Region)
	drop _m 
	drop if year>2015 
	egen totnbsal=sum(nbsal), by(sector)
	g postable=1
	replace postable=0 if totnbsal==0
	*constant variable at the province-level
	egen totemp=sum(employment), by(code_insee year)
	g totemp2003d=totemp if year==2003
	egen totemp2003=min(totemp2003d), by(code_insee)
	gen exposure_pre_pp=(nbsal2003/totemp2003)*100
	
	collapse (sum) employment (mean) pop  exposure_pre_pp, by(postable code_insee year)
	
	
	*Rank of pre-existing exposure 
	egen rankrelempd=xtile(exposure_pre_pp) if postable==1 & year==2004, nq(10) 
	egen rankrelemp=min(rankrelempd), by(code_insee)
	g top=.
	replace top=1 if rankrelemp>8 & rankrelemp!=.
	replace top=0 if rankrelemp<5 & rankrelemp!=.
	drop if top==.
	
    collapse (sum) employment pop, by(postable top year)
	
	g logemp=log(employment)
	g emprel=employment/pop
	foreach y in employment emprel{
	g normp`y'=`y' if year==2003
	egen norm`y'=min(normp`y'), by(top postable)
	g normemp`y'=`y'/norm`y'
	}

	g post=0
	replace post=1 if year>2003
	g interac=0
	replace interac=1 if postable==1 & top==1 & post==1
	g logemprel=log(emprel)

	reg logemprel i.top i.year i.top##i.post if postable==1 & year>1993, ro
    global beta=round(_b[1.top#1.post],.01)
	global se=round(_se[1.top#1.post],.01)

		
	twoway (connected normempemprel year if top==1 & postable==1 & year>1993, lcolor(cranberry) mcolor(cranberry)) ///
	(connected normempemprel year if top==0 & postable==1 & year>1993, lcolor(dknavy) mcolor(dknavy)), ///
	legend(label(1 "Top 10% Exposure") label(2 "Bottom 40% Exposure") cols(1) ring(0) pos(11)) ylabel(0.7 (0.3) 1.3) ///
	graphregion(fcolor(white) lcolor(white)) ///
	xlabel(1994 (1) 2015, angle(vertical)) xtitle("") ytitle("Share of Working Age Pop. in Postable Sectors (2003=1)") ///
	xline(2004, lcolor(red)) ///
	ttext(1.3 2010 "DiD: $beta($se)", place(e))
	 graph export "$replication_outputs_a/FigureD36d.pdf", replace	


	
	
